
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>

/*
 * ./button_led_test
 */
int main(int argc, char **argv)
{
	int led_fds[2];
	int button_fds[2];
	int status = 0;
	char file_name[100];
	int i;

	/* 2. 打开文件 */
	for (i = 0; i < 2; i++)
	{
		sprintf(file_name, "/dev/100ask_led%d", i);
		led_fds[i] = open(file_name, O_RDWR);

		sprintf(file_name, "/dev/100ask_button%d", i);
		button_fds[i] = open(file_name, O_RDWR);
	}

	while (1)
	{
		for (i = 0; i < 2; i++)
		{
			if (button_fds[i] != -1)
			{
				read(button_fds[i], &status, 1);
				
				if(led_fds[i] != -1) 
				{
					write(led_fds[i], &status, 4);
				}
			}
		}
	}
	
	return 0;
}


